package com.jie.langlangmall.portal.controller;

import com.jie.langlangmall.common.api.CommonPage;
import com.jie.langlangmall.common.api.CommonResult;
import com.jie.langlangmall.portal.domain.MemberBrandAttention;
import com.jie.langlangmall.portal.service.MemberAttentionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

/**
 * @Author Jie
 * @Date 2024/11/27
 * @Email 3217998214@qq.com
 * @Description 用户关注
 */
@RestController
@Tag(name = "MemberAttentionController", description = "会员关注品牌管理")
@RequestMapping("/member/attention")
public class MemberAttentionController {

    @Autowired
    private MemberAttentionService memberAttentionService;

    @Operation(summary = "关注品牌")
    @PostMapping("/add")
    public CommonResult<?> add(@RequestBody MemberBrandAttention memberBrandAttention) {
        memberAttentionService.add(memberBrandAttention);
        return CommonResult.success();
    }


    @Operation(summary = "取消关注")
    @PostMapping("/delete")
    public CommonResult<?> delete(@RequestParam("brandId") Long brandId) {
        memberAttentionService.delete(brandId);
        return CommonResult.success();
    }

    @Operation(summary = "查询用户关注列表")
    @GetMapping("/list")
    public CommonResult<CommonPage<MemberBrandAttention>> list(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                               @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize) {
        Page<MemberBrandAttention> page = memberAttentionService.list(pageNum, pageSize);
        return CommonResult.success(CommonPage.restPage(page));
    }

    @Operation(summary = "查询用户关注详情")
    @GetMapping("/detail")
    public CommonResult<MemberBrandAttention> detail(@RequestParam("brandId") Long brandId) {
        MemberBrandAttention memberBrandAttention = memberAttentionService.detail(brandId);
        return CommonResult.success(memberBrandAttention);
    }

    @Operation(summary = "清空关注列表")
    @PostMapping("/clear")
    public CommonResult<?> clear() {
        memberAttentionService.clear();
        return CommonResult.success();
    }

}
